<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples,
             ScopedTypeVariables #-}</span><span>
</span><span id="line-4"></span><span>
</span><span id="line-5"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-6"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- Module      :  Foreign.Marshal.Alloc</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- Copyright   :  (c) The FFI task force 2001</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- License     :  BSD-style (see the file libraries/base/LICENSE)</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- </span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Maintainer  :  ffi@haskell.org</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- Stability   :  provisional</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- Portability :  portable</span><span>
</span><span id="line-14"></span><span class="hs-comment">--</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- The module &quot;Foreign.Marshal.Alloc&quot; provides operations to allocate and</span><span>
</span><span id="line-16"></span><span class="hs-comment">-- deallocate blocks of raw memory (i.e., unstructured chunks of memory</span><span>
</span><span id="line-17"></span><span class="hs-comment">-- outside of the area maintained by the Haskell storage manager).  These</span><span>
</span><span id="line-18"></span><span class="hs-comment">-- memory blocks are commonly used to pass compound data structures to</span><span>
</span><span id="line-19"></span><span class="hs-comment">-- foreign functions or to provide space in which compound result values</span><span>
</span><span id="line-20"></span><span class="hs-comment">-- are obtained from foreign functions.</span><span>
</span><span id="line-21"></span><span class="hs-comment">-- </span><span>
</span><span id="line-22"></span><span class="hs-comment">-- If any of the allocation functions fails, an exception is thrown.</span><span>
</span><span id="line-23"></span><span class="hs-comment">-- In some cases, memory exhaustion may mean the process is terminated.</span><span>
</span><span id="line-24"></span><span class="hs-comment">-- If 'free' or 'reallocBytes' is applied to a memory area</span><span>
</span><span id="line-25"></span><span class="hs-comment">-- that has been allocated with 'alloca' or 'allocaBytes', the</span><span>
</span><span id="line-26"></span><span class="hs-comment">-- behaviour is undefined.  Any further access to memory areas allocated with</span><span>
</span><span id="line-27"></span><span class="hs-comment">-- 'alloca' or 'allocaBytes', after the computation that was passed to</span><span>
</span><span id="line-28"></span><span class="hs-comment">-- the allocation function has terminated, leads to undefined behaviour.  Any</span><span>
</span><span id="line-29"></span><span class="hs-comment">-- further access to the memory area referenced by a pointer passed to</span><span>
</span><span id="line-30"></span><span class="hs-comment">-- 'realloc', 'reallocBytes', or 'free' entails undefined</span><span>
</span><span id="line-31"></span><span class="hs-comment">-- behaviour.</span><span>
</span><span id="line-32"></span><span class="hs-comment">-- </span><span>
</span><span id="line-33"></span><span class="hs-comment">-- All storage allocated by functions that allocate based on a /size in bytes/</span><span>
</span><span id="line-34"></span><span class="hs-comment">-- must be sufficiently aligned for any of the basic foreign types</span><span>
</span><span id="line-35"></span><span class="hs-comment">-- that fits into the newly allocated storage. All storage allocated by</span><span>
</span><span id="line-36"></span><span class="hs-comment">-- functions that allocate based on a specific type must be sufficiently</span><span>
</span><span id="line-37"></span><span class="hs-comment">-- aligned for that type. Array allocation routines need to obey the same</span><span>
</span><span id="line-38"></span><span class="hs-comment">-- alignment constraints for each array element.</span><span>
</span><span id="line-39"></span><span class="hs-comment">--</span><span>
</span><span id="line-40"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-41"></span><span>
</span><span id="line-42"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Foreign.Marshal.Alloc</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-43"></span><span>  </span><span class="annot"><span class="hs-comment">-- * Memory allocation</span></span><span>
</span><span id="line-44"></span><span>  </span><span class="annot"><span class="hs-comment">-- ** Local allocation</span></span><span>
</span><span id="line-45"></span><span>  </span><span class="annot"><a href="Foreign.Marshal.Alloc.html#alloca"><span class="hs-identifier">alloca</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-46"></span><span>  </span><span class="annot"><a href="Foreign.Marshal.Alloc.html#allocaBytes"><span class="hs-identifier">allocaBytes</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-47"></span><span>  </span><span class="annot"><a href="Foreign.Marshal.Alloc.html#allocaBytesAligned"><span class="hs-identifier">allocaBytesAligned</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-48"></span><span>
</span><span id="line-49"></span><span>  </span><span class="annot"><span class="hs-comment">-- ** Dynamic allocation</span></span><span>
</span><span id="line-50"></span><span>  </span><span class="annot"><a href="Foreign.Marshal.Alloc.html#malloc"><span class="hs-identifier">malloc</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-51"></span><span>  </span><span class="annot"><a href="Foreign.Marshal.Alloc.html#mallocBytes"><span class="hs-identifier">mallocBytes</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-52"></span><span>
</span><span id="line-53"></span><span>  </span><span class="annot"><a href="Foreign.Marshal.Alloc.html#calloc"><span class="hs-identifier">calloc</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-54"></span><span>  </span><span class="annot"><a href="Foreign.Marshal.Alloc.html#callocBytes"><span class="hs-identifier">callocBytes</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-55"></span><span>
</span><span id="line-56"></span><span>  </span><span class="annot"><a href="Foreign.Marshal.Alloc.html#realloc"><span class="hs-identifier">realloc</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-57"></span><span>  </span><span class="annot"><a href="Foreign.Marshal.Alloc.html#reallocBytes"><span class="hs-identifier">reallocBytes</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-58"></span><span>
</span><span id="line-59"></span><span>  </span><span class="annot"><a href="Foreign.Marshal.Alloc.html#free"><span class="hs-identifier">free</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-60"></span><span>  </span><span class="annot"><a href="Foreign.Marshal.Alloc.html#finalizerFree"><span class="hs-identifier">finalizerFree</span></a></span><span>
</span><span id="line-61"></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-62"></span><span>
</span><span id="line-63"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Maybe.html"><span class="hs-identifier">Data.Maybe</span></a></span><span>
</span><span id="line-64"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.C.Types.html"><span class="hs-identifier">Foreign.C.Types</span></a></span><span>          </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CSize"><span class="hs-identifier">CSize</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-65"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.Storable.html"><span class="hs-identifier">Foreign.Storable</span></a></span><span>         </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier">Storable</span></a></span><span class="hs-special">(</span><span class="annot"><a href="Foreign.Storable.html#sizeOf"><span class="hs-identifier">sizeOf</span></a></span><span class="hs-special">,</span><span class="annot"><a href="Foreign.Storable.html#alignment"><span class="hs-identifier">alignment</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-66"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.ForeignPtr.html"><span class="hs-identifier">Foreign.ForeignPtr</span></a></span><span>       </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.ForeignPtr.html#FinalizerPtr"><span class="hs-identifier">FinalizerPtr</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-67"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Exception.html"><span class="hs-identifier">GHC.IO.Exception</span></a></span><span>
</span><span id="line-68"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Real.html"><span class="hs-identifier">GHC.Real</span></a></span><span>
</span><span id="line-69"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Ptr.html"><span class="hs-identifier">GHC.Ptr</span></a></span><span>
</span><span id="line-70"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-71"></span><span>
</span><span id="line-72"></span><span class="hs-comment">-- exported functions</span><span>
</span><span id="line-73"></span><span class="hs-comment">-- ------------------</span><span>
</span><span id="line-74"></span><span>
</span><span id="line-75"></span><span class="hs-comment">-- |Allocate a block of memory that is sufficient to hold values of type</span><span>
</span><span id="line-76"></span><span class="hs-comment">-- @a@.  The size of the area allocated is determined by the 'sizeOf'</span><span>
</span><span id="line-77"></span><span class="hs-comment">-- method from the instance of 'Storable' for the appropriate type.</span><span>
</span><span id="line-78"></span><span class="hs-comment">--</span><span>
</span><span id="line-79"></span><span class="hs-comment">-- The memory may be deallocated using 'free' or 'finalizerFree' when</span><span>
</span><span id="line-80"></span><span class="hs-comment">-- no longer required.</span><span>
</span><span id="line-81"></span><span class="hs-comment">--</span><span>
</span><span id="line-82"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Foreign.Marshal.Alloc.html#malloc"><span class="hs-pragma hs-type">malloc</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-83"></span><span class="annot"><a href="Foreign.Marshal.Alloc.html#malloc"><span class="hs-identifier hs-type">malloc</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679538071"><span class="annot"><a href="#local-6989586621679538071"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier hs-type">Storable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538071"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538071"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-84"></span><span id="malloc"><span class="annot"><span class="annottext">malloc :: forall a. Storable a =&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Alloc.html#malloc"><span class="hs-identifier hs-var hs-var">malloc</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO (Ptr a)
forall a. Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Alloc.html#mallocBytes"><span class="hs-identifier hs-var">mallocBytes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Int
forall a. Storable a =&gt; a -&gt; Int
</span><a href="Foreign.Storable.html#sizeOf"><span class="hs-identifier hs-var">sizeOf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
forall a. HasCallStack =&gt; a
</span><a href="GHC.Err.html#undefined"><span class="hs-identifier hs-var">undefined</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679538071"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-85"></span><span>
</span><span id="line-86"></span><span class="hs-comment">-- |Like 'malloc' but memory is filled with bytes of value zero.</span><span>
</span><span id="line-87"></span><span class="hs-comment">--</span><span>
</span><span id="line-88"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Foreign.Marshal.Alloc.html#calloc"><span class="hs-pragma hs-type">calloc</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-89"></span><span class="annot"><a href="Foreign.Marshal.Alloc.html#calloc"><span class="hs-identifier hs-type">calloc</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679537991"><span class="annot"><a href="#local-6989586621679537991"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier hs-type">Storable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537991"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537991"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-90"></span><span id="calloc"><span class="annot"><span class="annottext">calloc :: forall a. Storable a =&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Alloc.html#calloc"><span class="hs-identifier hs-var hs-var">calloc</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO (Ptr a)
forall a. Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Alloc.html#callocBytes"><span class="hs-identifier hs-var">callocBytes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Int
forall a. Storable a =&gt; a -&gt; Int
</span><a href="Foreign.Storable.html#sizeOf"><span class="hs-identifier hs-var">sizeOf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
forall a. HasCallStack =&gt; a
</span><a href="GHC.Err.html#undefined"><span class="hs-identifier hs-var">undefined</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679537991"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-91"></span><span>
</span><span id="line-92"></span><span class="hs-comment">-- |Allocate a block of memory of the given number of bytes.</span><span>
</span><span id="line-93"></span><span class="hs-comment">-- The block of memory is sufficiently aligned for any of the basic</span><span>
</span><span id="line-94"></span><span class="hs-comment">-- foreign types that fits into a memory block of the allocated size.</span><span>
</span><span id="line-95"></span><span class="hs-comment">--</span><span>
</span><span id="line-96"></span><span class="hs-comment">-- The memory may be deallocated using 'free' or 'finalizerFree' when</span><span>
</span><span id="line-97"></span><span class="hs-comment">-- no longer required.</span><span>
</span><span id="line-98"></span><span class="hs-comment">--</span><span>
</span><span id="line-99"></span><span id="local-6989586621679538067"><span class="annot"><a href="Foreign.Marshal.Alloc.html#mallocBytes"><span class="hs-identifier hs-type">mallocBytes</span></a></span><span>      </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538067"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-100"></span><span id="mallocBytes"><span class="annot"><span class="annottext">mallocBytes :: forall a. Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Alloc.html#mallocBytes"><span class="hs-identifier hs-var hs-var">mallocBytes</span></a></span></span><span> </span><span id="local-6989586621679537982"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537982"><span class="hs-identifier hs-var">size</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO (Ptr a) -&gt; IO (Ptr a)
forall a. String -&gt; IO (Ptr a) -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Alloc.html#failWhenNULL"><span class="hs-identifier hs-var">failWhenNULL</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;malloc&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CSize -&gt; IO (Ptr a)
forall a. CSize -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Alloc.html#_malloc"><span class="hs-identifier hs-var">_malloc</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; CSize
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537982"><span class="hs-identifier hs-var">size</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-101"></span><span>
</span><span id="line-102"></span><span class="hs-comment">-- |Llike 'mallocBytes' but memory is filled with bytes of value zero.</span><span>
</span><span id="line-103"></span><span class="hs-comment">--</span><span>
</span><span id="line-104"></span><span id="local-6989586621679537979"><span class="annot"><a href="Foreign.Marshal.Alloc.html#callocBytes"><span class="hs-identifier hs-type">callocBytes</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537979"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-105"></span><span id="callocBytes"><span class="annot"><span class="annottext">callocBytes :: forall a. Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Alloc.html#callocBytes"><span class="hs-identifier hs-var hs-var">callocBytes</span></a></span></span><span> </span><span id="local-6989586621679537975"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537975"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO (Ptr a) -&gt; IO (Ptr a)
forall a. String -&gt; IO (Ptr a) -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Alloc.html#failWhenNULL"><span class="hs-identifier hs-var">failWhenNULL</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;calloc&quot;</span></span><span> </span><span class="annot"><span class="annottext">(IO (Ptr a) -&gt; IO (Ptr a)) -&gt; IO (Ptr a) -&gt; IO (Ptr a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">CSize -&gt; CSize -&gt; IO (Ptr a)
forall a. CSize -&gt; CSize -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Alloc.html#_calloc"><span class="hs-identifier hs-var">_calloc</span></a></span><span> </span><span class="annot"><span class="annottext">CSize
</span><span class="hs-number">1</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; CSize
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537975"><span class="hs-identifier hs-var">size</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-106"></span><span>
</span><span id="line-107"></span><span class="hs-comment">-- |@'alloca' f@ executes the computation @f@, passing as argument</span><span>
</span><span id="line-108"></span><span class="hs-comment">-- a pointer to a temporarily allocated block of memory sufficient to</span><span>
</span><span id="line-109"></span><span class="hs-comment">-- hold values of type @a@.</span><span>
</span><span id="line-110"></span><span class="hs-comment">--</span><span>
</span><span id="line-111"></span><span class="hs-comment">-- The memory is freed when @f@ terminates (either normally or via an</span><span>
</span><span id="line-112"></span><span class="hs-comment">-- exception), so the pointer passed to @f@ must /not/ be used after this.</span><span>
</span><span id="line-113"></span><span class="hs-comment">--</span><span>
</span><span id="line-114"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Foreign.Marshal.Alloc.html#alloca"><span class="hs-pragma hs-type">alloca</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-115"></span><span class="annot"><a href="Foreign.Marshal.Alloc.html#alloca"><span class="hs-identifier hs-type">alloca</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679538051"><span class="annot"><a href="#local-6989586621679538051"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span id="local-6989586621679538050"><span class="annot"><a href="#local-6989586621679538050"><span class="hs-identifier hs-type">b</span></a></span></span><span> </span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier hs-type">Storable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538051"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538051"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538050"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538050"><span class="hs-identifier hs-type">b</span></a></span><span>
</span><span id="line-116"></span><span id="alloca"><span class="annot"><span class="annottext">alloca :: forall a b. Storable a =&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Alloc.html#alloca"><span class="hs-identifier hs-var hs-var">alloca</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span>
</span><span id="line-117"></span><span>  </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; (Ptr a -&gt; IO b) -&gt; IO b
forall a b. Int -&gt; Int -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Alloc.html#allocaBytesAligned"><span class="hs-identifier hs-var">allocaBytesAligned</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Int
forall a. Storable a =&gt; a -&gt; Int
</span><a href="Foreign.Storable.html#sizeOf"><span class="hs-identifier hs-var">sizeOf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
forall a. HasCallStack =&gt; a
</span><a href="GHC.Err.html#undefined"><span class="hs-identifier hs-var">undefined</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679538051"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Int
forall a. Storable a =&gt; a -&gt; Int
</span><a href="Foreign.Storable.html#alignment"><span class="hs-identifier hs-var">alignment</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
forall a. HasCallStack =&gt; a
</span><a href="GHC.Err.html#undefined"><span class="hs-identifier hs-var">undefined</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679538051"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-118"></span><span>
</span><span id="line-119"></span><span class="hs-comment">-- |@'allocaBytes' n f@ executes the computation @f@, passing as argument</span><span>
</span><span id="line-120"></span><span class="hs-comment">-- a pointer to a temporarily allocated block of memory of @n@ bytes.</span><span>
</span><span id="line-121"></span><span class="hs-comment">-- The block of memory is sufficiently aligned for any of the basic</span><span>
</span><span id="line-122"></span><span class="hs-comment">-- foreign types that fits into a memory block of the allocated size.</span><span>
</span><span id="line-123"></span><span class="hs-comment">--</span><span>
</span><span id="line-124"></span><span class="hs-comment">-- The memory is freed when @f@ terminates (either normally or via an</span><span>
</span><span id="line-125"></span><span class="hs-comment">-- exception), so the pointer passed to @f@ must /not/ be used after this.</span><span>
</span><span id="line-126"></span><span class="hs-comment">--</span><span>
</span><span id="line-127"></span><span id="local-6989586621679538044"><span id="local-6989586621679538045"><span class="annot"><a href="Foreign.Marshal.Alloc.html#allocaBytes"><span class="hs-identifier hs-type">allocaBytes</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538045"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538044"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538044"><span class="hs-identifier hs-type">b</span></a></span></span></span><span>
</span><span id="line-128"></span><span id="allocaBytes"><span class="annot"><span class="annottext">allocaBytes :: forall a b. Int -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Alloc.html#allocaBytes"><span class="hs-identifier hs-var hs-var">allocaBytes</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-type">I#</span></a></span><span> </span><span id="local-6989586621679537966"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679537966"><span class="hs-identifier hs-var">size</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679537965"><span class="annot"><span class="annottext">Ptr a -&gt; IO b
</span><a href="#local-6989586621679537965"><span class="hs-identifier hs-var">action</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, b #)) -&gt; IO b
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, b #)) -&gt; IO b)
-&gt; (State# RealWorld -&gt; (# State# RealWorld, b #)) -&gt; IO b
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679537964"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679537964"><span class="hs-identifier hs-var">s0</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-129"></span><span>     </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Int#
-&gt; State# RealWorld
-&gt; (# State# RealWorld, MutableByteArray# RealWorld #)
forall d. Int# -&gt; State# d -&gt; (# State# d, MutableByteArray# d #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#newPinnedByteArray%23"><span class="hs-identifier hs-var">newPinnedByteArray#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679537966"><span class="hs-identifier hs-var">size</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679537964"><span class="hs-identifier hs-var">s0</span></a></span><span>      </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679537963"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679537963"><span class="hs-identifier hs-var">s1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679537962"><span class="annot"><span class="annottext">MutableByteArray# RealWorld
</span><a href="#local-6989586621679537962"><span class="hs-identifier hs-var">mbarr#</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-130"></span><span>     </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">MutableByteArray# RealWorld
-&gt; State# RealWorld -&gt; (# State# RealWorld, ByteArray# #)
forall d.
MutableByteArray# d -&gt; State# d -&gt; (# State# d, ByteArray# #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#unsafeFreezeByteArray%23"><span class="hs-identifier hs-var">unsafeFreezeByteArray#</span></a></span><span> </span><span class="annot"><span class="annottext">MutableByteArray# RealWorld
</span><a href="#local-6989586621679537962"><span class="hs-identifier hs-var">mbarr#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679537963"><span class="hs-identifier hs-var">s1</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679537961"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679537961"><span class="hs-identifier hs-var">s2</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679537960"><span class="annot"><span class="annottext">ByteArray#
</span><a href="#local-6989586621679537960"><span class="hs-identifier hs-var">barr#</span></a></span></span><span>  </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-131"></span><span>     </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679537959"><span class="annot"><span class="annottext">addr :: Ptr a
</span><a href="#local-6989586621679537959"><span class="hs-identifier hs-var hs-var">addr</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Addr# -&gt; Ptr a
forall a. Addr# -&gt; Ptr a
</span><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-var">Ptr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ByteArray# -&gt; Addr#
</span><a href="../../ghc-prim/src/GHC.Prim.html#byteArrayContents%23"><span class="hs-identifier hs-var">byteArrayContents#</span></a></span><span> </span><span class="annot"><span class="annottext">ByteArray#
</span><a href="#local-6989586621679537960"><span class="hs-identifier hs-var">barr#</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">in</span><span>
</span><span id="line-132"></span><span>     </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Ptr a -&gt; IO b
</span><a href="#local-6989586621679537965"><span class="hs-identifier hs-var">action</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
forall {a}. Ptr a
</span><a href="#local-6989586621679537959"><span class="hs-identifier hs-var">addr</span></a></span><span>     </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span id="local-6989586621679537957"><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, b #)
</span><a href="#local-6989586621679537957"><span class="hs-identifier hs-var">action'</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-133"></span><span>     </span><span class="annot"><span class="annottext">ByteArray#
-&gt; State# RealWorld
-&gt; (State# RealWorld -&gt; (# State# RealWorld, b #))
-&gt; (# State# RealWorld, b #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#keepAlive%23"><span class="hs-identifier hs-var">keepAlive#</span></a></span><span> </span><span class="annot"><span class="annottext">ByteArray#
</span><a href="#local-6989586621679537960"><span class="hs-identifier hs-var">barr#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679537961"><span class="hs-identifier hs-var">s2</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, b #)
</span><a href="#local-6989586621679537957"><span class="hs-identifier hs-var">action'</span></a></span><span>
</span><span id="line-134"></span><span>  </span><span class="hs-special">}</span><span class="hs-special">}</span><span class="hs-special">}</span><span>
</span><span id="line-135"></span><span>
</span><span id="line-136"></span><span id="local-6989586621679538046"><span id="local-6989586621679538047"><span class="annot"><a href="Foreign.Marshal.Alloc.html#allocaBytesAligned"><span class="hs-identifier hs-type">allocaBytesAligned</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538047"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538046"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538046"><span class="hs-identifier hs-type">b</span></a></span></span></span><span>
</span><span id="line-137"></span><span id="allocaBytesAligned"><span class="annot"><span class="annottext">allocaBytesAligned :: forall a b. Int -&gt; Int -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Alloc.html#allocaBytesAligned"><span class="hs-identifier hs-var hs-var">allocaBytesAligned</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-type">I#</span></a></span><span> </span><span id="local-6989586621679537956"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679537956"><span class="hs-identifier hs-var">size</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-type">I#</span></a></span><span> </span><span id="local-6989586621679537955"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679537955"><span class="hs-identifier hs-var">align</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679537954"><span class="annot"><span class="annottext">Ptr a -&gt; IO b
</span><a href="#local-6989586621679537954"><span class="hs-identifier hs-var">action</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, b #)) -&gt; IO b
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, b #)) -&gt; IO b)
-&gt; (State# RealWorld -&gt; (# State# RealWorld, b #)) -&gt; IO b
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679537953"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679537953"><span class="hs-identifier hs-var">s0</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-138"></span><span>     </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Int#
-&gt; Int#
-&gt; State# RealWorld
-&gt; (# State# RealWorld, MutableByteArray# RealWorld #)
forall d.
Int# -&gt; Int# -&gt; State# d -&gt; (# State# d, MutableByteArray# d #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#newAlignedPinnedByteArray%23"><span class="hs-identifier hs-var">newAlignedPinnedByteArray#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679537956"><span class="hs-identifier hs-var">size</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679537955"><span class="hs-identifier hs-var">align</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679537953"><span class="hs-identifier hs-var">s0</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679537952"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679537952"><span class="hs-identifier hs-var">s1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679537951"><span class="annot"><span class="annottext">MutableByteArray# RealWorld
</span><a href="#local-6989586621679537951"><span class="hs-identifier hs-var">mbarr#</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-139"></span><span>     </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">MutableByteArray# RealWorld
-&gt; State# RealWorld -&gt; (# State# RealWorld, ByteArray# #)
forall d.
MutableByteArray# d -&gt; State# d -&gt; (# State# d, ByteArray# #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#unsafeFreezeByteArray%23"><span class="hs-identifier hs-var">unsafeFreezeByteArray#</span></a></span><span> </span><span class="annot"><span class="annottext">MutableByteArray# RealWorld
</span><a href="#local-6989586621679537951"><span class="hs-identifier hs-var">mbarr#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679537952"><span class="hs-identifier hs-var">s1</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679537950"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679537950"><span class="hs-identifier hs-var">s2</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679537949"><span class="annot"><span class="annottext">ByteArray#
</span><a href="#local-6989586621679537949"><span class="hs-identifier hs-var">barr#</span></a></span></span><span>  </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-140"></span><span>     </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679537948"><span class="annot"><span class="annottext">addr :: Ptr a
</span><a href="#local-6989586621679537948"><span class="hs-identifier hs-var hs-var">addr</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Addr# -&gt; Ptr a
forall a. Addr# -&gt; Ptr a
</span><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-var">Ptr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ByteArray# -&gt; Addr#
</span><a href="../../ghc-prim/src/GHC.Prim.html#byteArrayContents%23"><span class="hs-identifier hs-var">byteArrayContents#</span></a></span><span> </span><span class="annot"><span class="annottext">ByteArray#
</span><a href="#local-6989586621679537949"><span class="hs-identifier hs-var">barr#</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">in</span><span>
</span><span id="line-141"></span><span>     </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Ptr a -&gt; IO b
</span><a href="#local-6989586621679537954"><span class="hs-identifier hs-var">action</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
forall {a}. Ptr a
</span><a href="#local-6989586621679537948"><span class="hs-identifier hs-var">addr</span></a></span><span>     </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span id="local-6989586621679537947"><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, b #)
</span><a href="#local-6989586621679537947"><span class="hs-identifier hs-var">action'</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-142"></span><span>     </span><span class="annot"><span class="annottext">ByteArray#
-&gt; State# RealWorld
-&gt; (State# RealWorld -&gt; (# State# RealWorld, b #))
-&gt; (# State# RealWorld, b #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#keepAlive%23"><span class="hs-identifier hs-var">keepAlive#</span></a></span><span> </span><span class="annot"><span class="annottext">ByteArray#
</span><a href="#local-6989586621679537949"><span class="hs-identifier hs-var">barr#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679537950"><span class="hs-identifier hs-var">s2</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, b #)
</span><a href="#local-6989586621679537947"><span class="hs-identifier hs-var">action'</span></a></span><span>
</span><span id="line-143"></span><span>  </span><span class="hs-special">}</span><span class="hs-special">}</span><span class="hs-special">}</span><span>
</span><span id="line-144"></span><span>
</span><span id="line-145"></span><span class="hs-comment">-- |Resize a memory area that was allocated with 'malloc' or 'mallocBytes'</span><span>
</span><span id="line-146"></span><span class="hs-comment">-- to the size needed to store values of type @b@.  The returned pointer</span><span>
</span><span id="line-147"></span><span class="hs-comment">-- may refer to an entirely different memory area, but will be suitably</span><span>
</span><span id="line-148"></span><span class="hs-comment">-- aligned to hold values of type @b@.  The contents of the referenced</span><span>
</span><span id="line-149"></span><span class="hs-comment">-- memory area will be the same as of the original pointer up to the</span><span>
</span><span id="line-150"></span><span class="hs-comment">-- minimum of the original size and the size of values of type @b@.</span><span>
</span><span id="line-151"></span><span class="hs-comment">--</span><span>
</span><span id="line-152"></span><span class="hs-comment">-- If the argument to 'realloc' is 'nullPtr', 'realloc' behaves like</span><span>
</span><span id="line-153"></span><span class="hs-comment">-- 'malloc'.</span><span>
</span><span id="line-154"></span><span class="hs-comment">--</span><span>
</span><span id="line-155"></span><span class="annot"><a href="Foreign.Marshal.Alloc.html#realloc"><span class="hs-identifier hs-type">realloc</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679538029"><span class="annot"><a href="#local-6989586621679538029"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span id="local-6989586621679538030"><span class="annot"><a href="#local-6989586621679538030"><span class="hs-identifier hs-type">b</span></a></span></span><span> </span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier hs-type">Storable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538030"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538029"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538030"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-156"></span><span id="realloc"><span class="annot"><span class="annottext">realloc :: forall a b. Storable b =&gt; Ptr a -&gt; IO (Ptr b)
</span><a href="Foreign.Marshal.Alloc.html#realloc"><span class="hs-identifier hs-var hs-var">realloc</span></a></span></span><span> </span><span id="local-6989586621679537945"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537945"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO (Ptr b) -&gt; IO (Ptr b)
forall a. String -&gt; IO (Ptr a) -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Alloc.html#failWhenNULL"><span class="hs-identifier hs-var">failWhenNULL</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;realloc&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr a -&gt; CSize -&gt; IO (Ptr b)
forall a b. Ptr a -&gt; CSize -&gt; IO (Ptr b)
</span><a href="Foreign.Marshal.Alloc.html#_realloc"><span class="hs-identifier hs-var">_realloc</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537945"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">CSize
</span><a href="#local-6989586621679537943"><span class="hs-identifier hs-var">size</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-157"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-158"></span><span>    </span><span id="local-6989586621679537943"><span class="annot"><span class="annottext">size :: CSize
</span><a href="#local-6989586621679537943"><span class="hs-identifier hs-var hs-var">size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; CSize
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">b -&gt; Int
forall a. Storable a =&gt; a -&gt; Int
</span><a href="Foreign.Storable.html#sizeOf"><span class="hs-identifier hs-var">sizeOf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">b
forall a. HasCallStack =&gt; a
</span><a href="GHC.Err.html#undefined"><span class="hs-identifier hs-var">undefined</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679538030"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-159"></span><span>
</span><span id="line-160"></span><span class="hs-comment">-- |Resize a memory area that was allocated with 'malloc' or 'mallocBytes'</span><span>
</span><span id="line-161"></span><span class="hs-comment">-- to the given size.  The returned pointer may refer to an entirely</span><span>
</span><span id="line-162"></span><span class="hs-comment">-- different memory area, but will be sufficiently aligned for any of the</span><span>
</span><span id="line-163"></span><span class="hs-comment">-- basic foreign types that fits into a memory block of the given size.</span><span>
</span><span id="line-164"></span><span class="hs-comment">-- The contents of the referenced memory area will be the same as of</span><span>
</span><span id="line-165"></span><span class="hs-comment">-- the original pointer up to the minimum of the original size and the</span><span>
</span><span id="line-166"></span><span class="hs-comment">-- given size.</span><span>
</span><span id="line-167"></span><span class="hs-comment">--</span><span>
</span><span id="line-168"></span><span class="hs-comment">-- If the pointer argument to 'reallocBytes' is 'nullPtr', 'reallocBytes'</span><span>
</span><span id="line-169"></span><span class="hs-comment">-- behaves like 'malloc'.  If the requested size is 0, 'reallocBytes'</span><span>
</span><span id="line-170"></span><span class="hs-comment">-- behaves like 'free'.</span><span>
</span><span id="line-171"></span><span class="hs-comment">--</span><span>
</span><span id="line-172"></span><span id="local-6989586621679538024"><span class="annot"><a href="Foreign.Marshal.Alloc.html#reallocBytes"><span class="hs-identifier hs-type">reallocBytes</span></a></span><span>          </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538024"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538024"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-173"></span><span id="reallocBytes"><span class="annot"><span class="annottext">reallocBytes :: forall a. Ptr a -&gt; Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Alloc.html#reallocBytes"><span class="hs-identifier hs-var hs-var">reallocBytes</span></a></span></span><span> </span><span id="local-6989586621679537928"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537928"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">Ptr a -&gt; IO ()
forall a. Ptr a -&gt; IO ()
</span><a href="Foreign.Marshal.Alloc.html#free"><span class="hs-identifier hs-var">free</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537928"><span class="hs-identifier hs-var">ptr</span></a></span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Ptr a -&gt; IO (Ptr a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
forall {a}. Ptr a
</span><a href="GHC.Ptr.html#nullPtr"><span class="hs-identifier hs-var">nullPtr</span></a></span><span>
</span><span id="line-174"></span><span class="annot"><a href="Foreign.Marshal.Alloc.html#reallocBytes"><span class="hs-identifier hs-var">reallocBytes</span></a></span><span> </span><span id="local-6989586621679537926"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537926"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span id="local-6989586621679537925"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537925"><span class="hs-identifier hs-var">size</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span>
</span><span id="line-175"></span><span>  </span><span class="annot"><span class="annottext">String -&gt; IO (Ptr a) -&gt; IO (Ptr a)
forall a. String -&gt; IO (Ptr a) -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Alloc.html#failWhenNULL"><span class="hs-identifier hs-var">failWhenNULL</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;realloc&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr a -&gt; CSize -&gt; IO (Ptr a)
forall a b. Ptr a -&gt; CSize -&gt; IO (Ptr b)
</span><a href="Foreign.Marshal.Alloc.html#_realloc"><span class="hs-identifier hs-var">_realloc</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537926"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; CSize
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537925"><span class="hs-identifier hs-var">size</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-176"></span><span>
</span><span id="line-177"></span><span class="hs-comment">-- |Free a block of memory that was allocated with 'malloc',</span><span>
</span><span id="line-178"></span><span class="hs-comment">-- 'mallocBytes', 'realloc', 'reallocBytes', 'Foreign.Marshal.Utils.new'</span><span>
</span><span id="line-179"></span><span class="hs-comment">-- or any of the @new@/X/ functions in &quot;Foreign.Marshal.Array&quot; or</span><span>
</span><span id="line-180"></span><span class="hs-comment">-- &quot;Foreign.C.String&quot;.</span><span>
</span><span id="line-181"></span><span class="hs-comment">--</span><span>
</span><span id="line-182"></span><span id="local-6989586621679538022"><span class="annot"><a href="Foreign.Marshal.Alloc.html#free"><span class="hs-identifier hs-type">free</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538022"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-183"></span><span id="free"><span class="annot"><span class="annottext">free :: forall a. Ptr a -&gt; IO ()
</span><a href="Foreign.Marshal.Alloc.html#free"><span class="hs-identifier hs-var hs-var">free</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr a -&gt; IO ()
forall a. Ptr a -&gt; IO ()
</span><a href="Foreign.Marshal.Alloc.html#_free"><span class="hs-identifier hs-var">_free</span></a></span><span>
</span><span id="line-184"></span><span>
</span><span id="line-185"></span><span>
</span><span id="line-186"></span><span class="hs-comment">-- auxiliary routines</span><span>
</span><span id="line-187"></span><span class="hs-comment">-- -------------------</span><span>
</span><span id="line-188"></span><span>
</span><span id="line-189"></span><span class="hs-comment">-- asserts that the pointer returned from the action in the second argument is</span><span>
</span><span id="line-190"></span><span class="hs-comment">-- non-null</span><span>
</span><span id="line-191"></span><span class="hs-comment">--</span><span>
</span><span id="line-192"></span><span id="local-6989586621679538060"><span class="annot"><a href="Foreign.Marshal.Alloc.html#failWhenNULL"><span class="hs-identifier hs-type">failWhenNULL</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538060"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538060"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-193"></span><span id="failWhenNULL"><span class="annot"><span class="annottext">failWhenNULL :: forall a. String -&gt; IO (Ptr a) -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Alloc.html#failWhenNULL"><span class="hs-identifier hs-var hs-var">failWhenNULL</span></a></span></span><span> </span><span id="local-6989586621679537919"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679537919"><span class="hs-identifier hs-var">name</span></a></span></span><span> </span><span id="local-6989586621679537918"><span class="annot"><span class="annottext">IO (Ptr a)
</span><a href="#local-6989586621679537918"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-194"></span><span>   </span><span id="local-6989586621679537917"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537917"><span class="hs-identifier hs-var">addr</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO (Ptr a)
</span><a href="#local-6989586621679537918"><span class="hs-identifier hs-var">f</span></a></span><span>
</span><span id="line-195"></span><span>   </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537917"><span class="hs-identifier hs-var">addr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a -&gt; Ptr a -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
forall {a}. Ptr a
</span><a href="GHC.Ptr.html#nullPtr"><span class="hs-identifier hs-var">nullPtr</span></a></span><span>
</span><span id="line-196"></span><span>      </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">IOError -&gt; IO (Ptr a)
forall a. IOError -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioError"><span class="hs-identifier hs-var">ioError</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe Handle
-&gt; IOErrorType
-&gt; String
-&gt; String
-&gt; Maybe CInt
-&gt; Maybe String
-&gt; IOError
</span><a href="GHC.IO.Exception.html#IOError"><span class="hs-identifier hs-var">IOError</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Handle
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">IOErrorType
</span><a href="GHC.IO.Exception.html#ResourceExhausted"><span class="hs-identifier hs-var">ResourceExhausted</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679537919"><span class="hs-identifier hs-var">name</span></a></span><span> </span><span>
</span><span id="line-197"></span><span>                                        </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;out of memory&quot;</span></span><span> </span><span class="annot"><span class="annottext">Maybe CInt
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe String
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-198"></span><span>      </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Ptr a -&gt; IO (Ptr a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537917"><span class="hs-identifier hs-var">addr</span></a></span><span>
</span><span id="line-199"></span><span>
</span><span id="line-200"></span><span class="hs-comment">-- basic C routines needed for memory allocation</span><span>
</span><span id="line-201"></span><span class="hs-comment">--</span><span>
</span><span id="line-202"></span><span id="local-6989586621679538059"><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;stdlib.h malloc&quot;</span></span><span>  </span><span id="_malloc"><span class="annot"><a href="Foreign.Marshal.Alloc.html#_malloc"><span class="hs-identifier hs-var">_malloc</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span>          </span><span class="annot"><a href="Foreign.C.Types.html#CSize"><span class="hs-identifier hs-type">CSize</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538059"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-203"></span><span id="local-6989586621679538052"><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;stdlib.h calloc&quot;</span></span><span>  </span><span id="_calloc"><span class="annot"><a href="Foreign.Marshal.Alloc.html#_calloc"><span class="hs-identifier hs-var">_calloc</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CSize"><span class="hs-identifier hs-type">CSize</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CSize"><span class="hs-identifier hs-type">CSize</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538052"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-204"></span><span id="local-6989586621679538025"><span id="local-6989586621679538026"><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;stdlib.h realloc&quot;</span></span><span> </span><span id="_realloc"><span class="annot"><a href="Foreign.Marshal.Alloc.html#_realloc"><span class="hs-identifier hs-var">_realloc</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538026"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CSize"><span class="hs-identifier hs-type">CSize</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538025"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span></span></span><span>
</span><span id="line-205"></span><span id="local-6989586621679537913"><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;stdlib.h free&quot;</span></span><span>    </span><span id="_free"><span class="annot"><a href="Foreign.Marshal.Alloc.html#_free"><span class="hs-identifier hs-var">_free</span></a></span></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537913"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-206"></span><span>
</span><span id="line-207"></span><span class="hs-comment">-- | A pointer to a foreign function equivalent to 'free', which may be</span><span>
</span><span id="line-208"></span><span class="hs-comment">-- used as a finalizer (cf 'Foreign.ForeignPtr.ForeignPtr') for storage</span><span>
</span><span id="line-209"></span><span class="hs-comment">-- allocated with 'malloc', 'mallocBytes', 'realloc' or 'reallocBytes'.</span><span>
</span><span id="line-210"></span><span id="local-6989586621679537912"><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;stdlib.h &amp;free&quot;</span></span><span> </span><span id="finalizerFree"><span class="annot"><a href="Foreign.Marshal.Alloc.html#finalizerFree"><span class="hs-identifier hs-var">finalizerFree</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.ForeignPtr.html#FinalizerPtr"><span class="hs-identifier hs-type">FinalizerPtr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537912"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-211"></span><span>
</span><span id="line-212"></span></pre></body></html>